﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Remoting;
using System.Reflection;
using System.Threading;

namespace Tommy
{
    public class Loader
    {
        IUILoader uiloader;
        public Loader()
        {
            
            
        }
        private bool Show(ref Context context)
        {
            uiloader.OnFormEx_Show();
            return true;
        }
        private bool InitUserPlugins(ref Context context)
        {
            uiloader.UpdateProgressText("Initializing Plugins...");
            Thread.Sleep(100);
            Plugin plugin = new Plugin();
            plugin.Name = "Check In";
            context.currentUser.Modules.Add(plugin);
            plugin = new Plugin();
            plugin.Name = "Check Out";
            context.currentUser.Modules.Add(plugin);
            plugin = new Plugin(); 
            plugin.Name = "Configuration";
            context.currentUser.Modules.Add(plugin);
            plugin = new Plugin(); 
            plugin.Name = "Setup Warehouse";
            context.currentUser.Modules.Add(plugin);
            plugin = new Plugin(); 
            plugin.Name = "e";
            context.currentUser.Modules.Add(plugin);
            plugin = new Plugin(); 
            plugin.Name = "f";
            context.currentUser.Modules.Add(plugin);
            return true;
        }
        private bool InitDB(ref Context context)
        {
            Thread.Sleep(100);
            uiloader.UpdateProgressText("Initializing database connection...");
            return true;
        }
        private bool Login(ref Context context)
        {
            uiloader.UpdateProgressText("Login");
            Thread.Sleep(100);
            return true;
        }
        public bool InitializeEventTable()
        {
            EventTable.event_loader_initializing += LoadPlugin;            
            EventTable.event_loader_initializing += InitDB;
            EventTable.event_loader_initializing += InitUserPlugins;
            EventTable.event_loader_initializing += Login;
            EventTable.event_loader_show += Show;
            return true;
        }

        private bool LoadPlugin(ref Context context)
        {
            uiloader = System.Activator.CreateInstance("Tommy.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d63bf6103442dbdd", "Tommy.UILoader").Unwrap() as IUILoader;
            return true;
        }

       

    }
}
